<xsl:stylesheet version="1.0"
                xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
                xmlns:ord="http://orders.team1.imse" xmlns:data="http://data.orders.team1.imse"
                xmlns:inv="http://inventory.team1.imse" xmlns:dist="http://distancetowarehouses.team1.imse"
                xmlns:distd="http://data.roaddistances.team1.imse"
                xmlns:exslt="http://exslt.org/common" exclude-result-prefixes="ord distd dist exslt">

    <xsl:output indent="yes" omit-xml-declaration="yes" method="xml"/>

    <xsl:strip-space elements="*"/>

    <xsl:param name="Warehouses"/>
    <xsl:variable name="nswarehouses" select="exslt:node-set($Warehouses)/dist:distancesToWarehouses"/>

    <xsl:template match="ord:placeOrderReqElement">
        <inv:bookOrderReqElement>
            <inv:clientID>
                <xsl:value-of select="ord:clientID"/>
            </inv:clientID>
            <inv:clientLocation>
                <data:city>
                    <xsl:value-of select="ord:location"/>
                </data:city>
            </inv:clientLocation>
            <xsl:apply-templates select="ord:orderItem"/>
            <!--<inv:warehouseLocation>
                <data:city><xsl:value-of select="$nswarehouses"/></data:city>
            </inv:warehouseLocation>-->
            <xsl:for-each select="$nswarehouses/distd:distanceToWarehouse">
                <xsl:variable name="i" select="position()"/>
                <inv:warehouseLocation>
                    <data:city>
                        <xsl:value-of select="$nswarehouses/distd:distanceToWarehouse[$i]/distd:warehouseLocation"/>
                    </data:city>
                </inv:warehouseLocation>
            </xsl:for-each>
        </inv:bookOrderReqElement>
    </xsl:template>

    <xsl:template match="ord:orderItem">
        <inv:orderItem>
            <xsl:apply-templates select="data:name"/>
            <xsl:apply-templates select="data:qty"/>
        </inv:orderItem>
    </xsl:template>
    <xsl:template match="data:name">
        <data:name>
            <xsl:value-of select="."/>
        </data:name>
    </xsl:template>
    <xsl:template match="data:qty">
        <data:qty>
            <xsl:value-of select="."/>
        </data:qty>
    </xsl:template>

</xsl:stylesheet>